//
// Created by 赵李言 on 2022/4/11.
//

#include <iostream>
using namespace std;
int m,l;
bool ts[10050];
int main(int argc, char**argv) {
    //freopen("tree.in", "r", stdin);
 //   freopen("tree.out", "w", stdout);
    cin>>l>>m;
    memset(ts, 0,10050);
    for (int i = 0; i < m; ++i) {
        int a,b;
        cin>>a>>b;
        for (int j = a; j <= b; ++j) {
            ts[j]=1;
        }
    }
    int sum = 0;
    for (int i = 0; i <= l; ++i) {
        if(!ts[i]){
            sum++;
        }
    }
    cout<<sum;
}